<?php
//占位
//非实质性操作
trait trait_gdpx
{
//-------------------------------------------------------------------------------

	function allClear()
	{
		$this->all = array();
	}
//-------------------------------------------------------------------------------
	//全部颜色矩阵
	function allColor()
	{
		if(empty($this->all))
		{
			for($i = 0; $i < $this->sw; $i ++)
			{
				for($j = 0; $j < $this->sh; $j ++)
				{
					$this->all[$i][$j] = $this->index2color(imagecolorat($this->handle, $i, $j));
				}
			}
		}
	}
//-------------------------------------------------------------------------------
	function likecolor_easy_range($int, $range)
	{
		$s = $int - $range;
		$s = $s < 0 ? 0 : $s;
		$e = $int + $range;
		$e = $e > 15 ? 15 : $e;
		
		return range($s, $e);
	}
//-------------------------------------------------------------------------------
	function likecolor($color, $range = 3)
	{
		$color = $this->formatColor($color);
		
		if($range === null)
			$range = 3;
		
		$a1 = $this->likecolor_easy_range($this->formatColor2int($color{0}), $range);
		$a2 = $this->likecolor_easy_range($this->formatColor2int($color{1}), $range);
		$a3 = $this->likecolor_easy_range($this->formatColor2int($color{2}), $range);
		$a4 = $this->likecolor_easy_range($this->formatColor2int($color{3}), $range);
		$a5 = $this->likecolor_easy_range($this->formatColor2int($color{4}), $range);
		$a6 = $this->likecolor_easy_range($this->formatColor2int($color{5}), $range);
		
		$new = array();
		foreach($a1 as $v1)
		{
			foreach($a2 as $v2)
			{
				foreach($a3 as $v3)
				{
					foreach($a4 as $v4)
					{
						foreach($a5 as $v5)
						{
							foreach($a6 as $v6)
							{
								$tmp = $this->formatColor2char($v1).$this->formatColor2char($v2).$this->formatColor2char($v3).$this->formatColor2char($v4).$this->formatColor2char($v5).$this->formatColor2char($v6);
								$new[$tmp] = $tmp;
							}
						}
					}
				}
			}
		}
		
		return $new;
	}
//-------------------------------------------------------------------------------

	//$type 0是横线 1是竖线
	function findfullline($type, $one, $color, $rc1, $rc2, $range = null)
	{
		$this->fictitiousReplaceColor($color, $rc1, $range);
		$this->fictitiousReplaceColorNo($rc1, $rc2);
		
		$pxs = $type == 0 ? array_extract($this->all) : $this->all;		
		$new = array();
		foreach($pxs as $k => $v)
		{
			$tmp = array_unique($v);
			
			if(count($tmp) == 1 && current($tmp) == $rc1)
			{
				if($one)
					return $k;
				
				$new[] = $k;
			}
		}
		
		if($one)
			return 0;
		
		return $new;
	}
//-------------------------------------------------------------------------------

	//虚拟换颜色
	function fictitiousReplaceColor($color, $replace, $range = 20)
	{
		$this->allColor();
		$array = $this->likeColor($color, $range);
		$replace = $this->formatColor($replace);
		
		for($i = 0; $i < $this->sw; $i ++)
		{
			for($j = 0; $j < $this->sh; $j ++)
			{
				if(isset($array[$this->all[$i][$j]]))
				{
					$this->all[$i][$j] = $replace;
				}
			}
		}
	}
//-------------------------------------------------------------------------------
//虚拟换颜色
	function fictitiousReplaceColorNo($color, $replace, $range = 5)
	{
		$this->allColor();		
		$array = $this->likeColor($color, $range);		
		$replace = $this->formatColor($replace);
				
		for($i = 0; $i < $this->sw; $i ++)
		{
			for($j = 0; $j < $this->sh; $j ++)
			{				
				if(!isset($array[$this->all[$i][$j]]))
				{
					$this->all[$i][$j] = $replace;
				}
			}
		}


	}
}